//判断二叉树是否相似
#include<stdio.h>
#include<malloc.h>
#include <iostream>
#include<string>
using namespace std;

typedef struct treenode {
    char data;
    struct treenode* lchild, * rchild;
}treenode, * tree;

void buildtree(tree& t) {
char ch;
//ch = getchar();
cin >> ch;
if (ch == '#')t = NULL;
else {
t = (treenode*)malloc(sizeof(treenode));
t->data = ch;
t->lchild = NULL;
t->rchild = NULL;
buildtree(t->lchild);
buildtree(t->rchild);
}
}
int similar(tree t1, tree t2) {
    int left, right;
    if (t1 == NULL && t2 == NULL)return 1;
    else if (t1 == NULL || t2 == NULL)return 0;
    else {
        left = similar(t1->lchild, t2->lchild);
        right = similar(t1->rchild, t2->rchild);
        return(left && right);
    }
    return 0;
}
int main() {
    tree t1, t2;
    buildtree(t1);
    buildtree(t2);
    printf("%d\n", similar(t1, t2));
    return 0;
}
//AB###
//C#E##